package com.xnx3.j2ee.system;

import com.xnx3.j2ee.log.Log;
import com.xnx3.j2ee.pojo.constant.LogOption;
import com.xnx3.j2ee.util.ConsoleUtil;
import org.springframework.boot.CommandLineRunner;
import org.springframework.context.annotation.Configuration;

import javax.annotation.Resource;

/**
 * @Description: wangmarket
 * @Author xiaoliangjun
 * @DateTime 4/1/24 10:24 AM
 */
@Configuration
public class LogConfig implements CommandLineRunner {

    private Log log;

    @Resource
        private LogOption logOption;

        /**
         * 加载配置 {@link （aplication.properties/yml）文件的配置数据，通过其属性来决定使用何种配置。
         * <br>这个其实就相当于用java代码来动态决定配置
         * @param config
         */
        public void loadConfig(LogOption config) {

            log.loadConfig(config); //加载application配置
        }




        @Override
        public void run(String... args) throws Exception {
            ConsoleUtil.debug("load log config by application.properties / yml : "+this.logOption);
            if(log == null) {
                log = new Log();
            }
            loadConfig(this.logOption); //加载application配置
        }

}
